﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        List<string> factorstrings = new List<string>();
        List<int> factorslocal = new List<int>();
        int xaxis = 0;
        int yaxis = 0;
        public Form2(List<int> factors, int xaxis, int yaxis)
        {
            InitializeComponent();
            factorslocal.Clear();
            factorslocal = factors;
            for (int i = 0; i <= factors.Count-1; i++)
            {
                factorstrings.Add(factors[i].ToString() + " x " + (factors[factors.Count - 1]/factors[i]).ToString());
            }
            comboBox1.DataSource = factorstrings;
            this.xaxis = xaxis;
            this.yaxis = yaxis;
            textBox1.Text = "1";
            comboBox1.Focus();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 form = (Form1)this.Owner;
            form.sety(factorslocal[comboBox1.SelectedIndex]);
            form.setx(factorslocal[factorslocal.Count - 1]/factorslocal[comboBox1.SelectedIndex]);
            form.setxed(false);
            try
            {
                ((Form1)this.Owner).times = int.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("I'm sorry, that is not a valid number of charts to create.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox1.Clear();
                return;
            }
            this.Close();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                e.Handled = true;
                button1_Click(this, e);
            }
            else
            {
                e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
            }
        }

        private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                e.Handled = true;
                button1_Click(this, e);
            }
        }
    }
}
